import joblib
import pandas as pd
from sklearn.metrics import accuracy_score, roc_auc_score, recall_score, f1_score, confusion_matrix

es=joblib.load("../model/xgb_20250604.pkl")

data = pd.read_csv('../data/test2.csv')
feature_data = data.copy()
x_test = feature_data[['MaritalStatus', 'Department',
                  'JobRole', 'OverTime', 'JobSatisfaction',
                  'MonthlyIncome', 'YearsSinceLastPromotion', 'BusinessTravel',
                  'WorkLifeBalance', 'Age', 'YearsAtCompany',
                  'DistanceFromHome', 'EnvironmentSatisfaction', 'NumCompaniesWorked']]

x_test = pd.get_dummies(x_test)

y_test = feature_data['Attrition']

y_pred_proba = es.predict_proba(x_test)[:, 1]
threshold = 0.71
y_pred = (y_pred_proba > threshold).astype(int)

print(f"准确率: {accuracy_score(y_test, y_pred):.4f}")